package com.sharkburner.common.dao.paginator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.vaadin.addons.lazyquerycontainer.Query;

import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;

@Component
@Scope("prototype")
public class PaginatorCriteria implements Query, Serializable {

    private LazyFactory factory;

    public PaginatorCriteria() {
    }

    @Override
    public Item constructItem() {
	// TODO Auto-generated method stub
	return null;
    }

    @Override
    public boolean deleteAllItems() {
	// TODO Auto-generated method stub
	return false;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Item> loadItems(int startIndex, int count) {
	List<Item> resultItems = new ArrayList<Item>();
	for (Object object : factory.getList(startIndex, count)) {
	    resultItems.add(new BeanItem(object));
	}

	return resultItems;
    }

    @Override
    public void saveItems(List<Item> arg0, List<Item> arg1, List<Item> arg2) {
	// TODO Auto-generated method stub

    }

    @Override
    public int size() {
	return factory.getSize();
    }

    public void setFactory(LazyFactory factory) {
	this.factory = factory;
    }
}
